The present invention relates to a technique to increase the speed of a light source calculation (brightness calculation, illumination processing) to determine the colors of vertices of a figure from information, such as vertices of a figure, light sources, the position of a viewing point, colors and normal vectors, to see how the figure looks when illuminated by a plurality of light sources during the shading processing (shading, half-tone processing) in a computer graphics system.
Specifically, this invention relates to a graphics processor to determine colors by performing the light source calculation mentioned above and to a graphics system using the graphics processor.
The computer graphics system displays the output of a computer in the form of figures.
The light source calculation in the shading processing in a conventional computer graphics system is detailed in pOpenGL Programmnig Guide (Japanese version), published by Seiunsha, 1993, pp. 157-194.
The computer graphics system performs geometric processing and rendering processing. The geometric processing includes coordinate conversion of vertices of a figure and light source calculation to calculate colors of the vertices from information about, e.g., vertices of a figure, a light source, a viewing point position, colors and normal vectors, to see how the figure looks. The rendering processing involves developing and drawing pixels inside the figure one by one based on information about vertex coordinates and colors and so on. After the geometric processing and the rendering processing, the computer graphics system writes the contents to be displayed on the screen into a frame memory that stores data in a bit map format.
The computer graphics system generally represents pixel data by color data rgba (red, green, blue, alpha) of a figure, and performs the geometric processing in the float type and the rendering processing in the short-int type.
Here, the float type represents 32-bit floating point real numbers, the int type represents 32-bit integers (including fixed point real numbers), and the short int type represents 8- to 16-bit integers.
For the sake of simplicity, we assume that the short int type is 16-bit integers.
Now, let us explain about the computer graphics system whose color data of the pixel data in the frame memory are 8 bits (=1 byte) for each color component, or 32 bits in total.
The conventional light source computation calculates light source formulas such as Equation 4 in a float type which has large hardware quantities and is slow.
(Each component of rgb is calculated independently by Equation 4, and no calculation is performed on the component a. I.a=a)                     [                  Equation          ⁢                      xe2x80x83                    ⁢          4                ]                            xe2x80x83                                I        =                  Ke          +                      Ka            ⁢                          xe2x80x83                        ⁢            þ            ⁢                          xe2x80x83                        ⁢            Lcta                    +                                                                      [                                      xe2x80x83                                    ⁢                                                                                                              xe2x80x83                                                ∑                                                                    i                        =                        1                                            n                                        [                                          xe2x80x83                                        ⁢                                                                  Ka                        xc3x97                                                  Lca                          .                          i                                                                    +                                              Kd                        xc3x97                                                  Lcd                          .                          i                                                xc3x97                                                  (                                                      N                            ·                                                          L                              .                              i                                                                                )                                                                    +                                              Ks                        xc3x97                                                  Lcs                          .                          i                                                xc3x97                                                                              (                                                          N                              ·                                                              H                                .                                i                                                                                      )                                                    ^                          SM                                                                                                                    }                            xc3x97                              At                .                i                            xc3x97                              Sp                .                i                                      ]                                              Equation        ⁢                  xe2x80x83                ⁢                  (          4          )                    
where
m is the number of light sources;
i (i=1 to m) is a light source;
I=(I.r, I.g, I.b, I.a) is a color calculated by the light source computation;
Ka=(Ka.r, Ka.g, Ka.b) is a ambient reflection coefficient of a material;
Kd=(Kd.r, Kd.g, Kd.b) is a diffuse reflection coefficient of a material;
Ks=(Ks.r, Ks.g, Ks.b) is a mirror surface reflection coefficient of a material;
Ke=(Ke.r, Ke.g, Ke.b) is a radial reflection coefficient of a material;
SM (0.0xe2x89xa6SMxe2x89xa6128.0) is a mirror surface index of a material;
Lcta=(Lcta.r, Lcta.g, Lcta.b) is a color for each reflected light of an overall background light source;
Lca.i=(Lca.r.i, Lca.g.i, Lca.b.i) is a color for background reflection light from a light source;
Lcd.i=(Lcd.r.i, Lcd.g.i, Lcd.b.i) is a color for diffuse reflection light from a light source;
Lcs.i=(Lcs.r.i, Lcs.g.i, Lcs.b.i) is a color for mirror surface reflection light from a light source;
Normal vector N=(Nx, Ny, Nz);
Light source direction vector L.i=(Lx.i, Ly.i, Lz.i);
Halfway vector (maximum highlight direction vector)
H.i=(Hx.i, Hy.i, Hz.i),
H.i=(V+L.i)/{grave over (p)}V+L.i{grave over (p)} where {grave over (p)}V+L.i{grave over (p)} is a magnitude of (V+L.i) sight direction vector V=(Vx, Vy, Vz) Each vector having a magnitude of 1.
It is assumed that (Nxc2x7L.i)=0 when (Nxc2x7L.i)xe2x89xa70: (Nxc2x7L.i) less than 0.
It is also assumed that (Nxc2x7H.i)=0 when (Nxc2x7H.i)xe2x89xa70.
Further, it is assumed that (Nxc2x7H.i)=0 also when (Nxc2x7L.i)xe2x89xa60.
Here, the attenuation coefficient At.i and the spot light source effect Sp.i are defined as follows:
At.i=1 for parallel light sources
=1/(Kc+Klpd+Kqpd{circumflex over ( )}2): for point light sources and spot light sources
where Kc, Kl, Kq are attenuation constants and d is the distance from the light source to the vertex.
Sp.i=1: for parallel light sources and point light sources
=(xe2x88x92SD.ixc2x7L.i){circumflex over ( )}SE.i: within the illumination range of a spot light source (xe2x88x92SD.ixc2x7L.i)xe2x89xa7cos(SC.i)
=0: outside the illumination range of a spot light source (xe2x88x92SD.ixc2x7L.i) less than cos(SC.i)
where SD.i=(SDx.i, SDy.k, SDz.i) is the spot light source direction vector;
SE.i is the spot light index; and
SC.i is the cutoff index of a spot light source.
FIG. 6 shows the relation among the above vectors.
The conventional light source computation calculates these complex light source formulas in a float type that has large hardware quantities and is slow. Therefore, the light source computation requires a large quantity of float type calculations, and hence the conventional computer graphics systems use a geometry processor GP dedicated to the geometric processing to perform the light source computation by software. This requires a huge amount of time for the light source computation.
The conventional computer graphics systems have a problem that although each component of the color data rgba in the frame memory are 8-bit data, the conventional light source computation requires performing a great amount of slow float type calculation (32 bits) containing many hardware quantities and spends a vast amount of time.
An object of the present invention is to provide a graphics processor and a graphics system, which can perform light source computations in shading processing at significantly high speeds.
The graphics processor of this invention comprises: a light source table holding light source data; a conversion unit for converting the light source data to be set in the light source table from a float type (single-precision floating point real number type) into an int type (integer type); an inner product calculation unit for calculating the inner product of the normal directions, light source directions and sight line directions at vertices of at least a three-dimensional figure according to the light source data; and a color calculation unit for performing light source computations based on the calculated inner products to determine colors of vertices.
With the above configuration, the light source computation of int type can be executed, increasing the speed of the light source computations in shading processing and therefore the speed of the figure drawing processing.
Further, the graphics system o this invention comprises: a graphics processor for determining colors of vertices of at least a three-dimensional figure by calculating the inner products of normal directions, light source directions and sight line directions at each of the vertices; a frame memory; a rendering processor for interpolating pixels inside the figure based on the calculated colors of the vertices and writing the pixel into the frame memory; and a display device; wherein the graphics processor includes: a light source table holding light source data; a conversion unit for converting the light source data to be set in the light source table from a float type (single-precision floating point real number type) into an int type (integer type); an inner product calculation unit for calculating the inner products of normal directions, light source directions and sight line directions at the vertices according to the light source data; and a color calculation unit for performing light source computations based on the calculated inner products to determine colors of vertices.
With the above configuration, it is possible to increase the speed of the light source computations in shading processing and also the speed of the figure drawing processing.
Further, in the graphics processor of this invention each of the m light source data held in the light source table has a light source computation in-process flag which represents whether the light source computation on the light source data is being performed, and a light source table control unit is provided, which, at the start of the light source computation, locks the flags for all light source data and, each time the light source computation is finished for one light source data, unlocks the corresponding flag. With this configuration, each time the light source computation is finished for one light source, new light source data can be set immediately in areas in the light source table for which the corresponding flags are unlocked (data areas for which the light source computation has ended). This allows quick setting of data even when the light source data areas in the light source table that are available for setting are few.